using System;
using StreetlightGames.SpaceShooter.WaveMetaData;
using System.IO;

namespace StreetlightGames.SpaceShooter
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.  Supports 2 optional command-line parameters.
        /// The first parameter is the wave data file name.  The second parameter is the zero-based wave index.
        /// </summary>
        /// <param name="args">Command-line arguments</param>
        static void Main(string[] args)
        {
            using (SpaceShooterGame game = new SpaceShooterGame())
            {
                if (args.Length == 1 && File.Exists(args[0]))
                {
                    WaveDataCollection waveData = WaveDataCollection.FromFile(args[0]);
                    game.LoadWaves(waveData);
                }
                else if (args.Length == 2)
                {
                    WaveDataCollection allWaves = WaveDataCollection.FromFile(args[0]);
                    WaveDataCollection waveData = new WaveDataCollection();
                    int waveIndex;
                    if (int.TryParse(args[1], out waveIndex))
                    {
                        if (waveIndex >= 0 && waveIndex < allWaves.Count)
                        {
                            waveData.Add(allWaves[waveIndex]);
                            game.LoadWaves(waveData);
                        }
                    }
                }
                else if (File.Exists("WaveData.xml"))
                {
                    WaveDataCollection waveData = WaveDataCollection.FromFile("WaveData.xml");
                    game.LoadWaves(waveData);
                }
                game.Run();
            }
        }
    }
}